package xzr2;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Random;
import java.util.Scanner;

//1. 酒店前台管理程序
class Room{
    String[][] rooms = new String[12][10];

    public Room() {//初始化
        for (int i = 0; i < rooms.length; i++) {
            for (int j = 0; j < rooms[i].length; j++) {
                rooms[i][j] = "空";
            }
        }
    }
    public void show(){
        for (int i = 0; i < rooms.length; i++) {
            for (int j = 0; j < rooms[i].length; j++) {
                System.out.print(rooms[i][j] + "\t");

            }
            System.out.println();
        }
    }
    public void inRoom(String name,int room){ //1201
        int i = room/100;
        int j = room%100;
        rooms[i-1][j-1] = name;
    }
    public void outRoom(int room){ //1201
        int i = room/100;
        int j = room%100;
        rooms[i-1][j-1] = "空";
    }
}

class Score{
    String[] names = { "张三丰", "郭靖", "乔峰", "张无忌", "杨过" };
    String[] cNames = { "JAVA", "C++", "Oracle", "Android" };
    static int[][] score = { { 87, 76, 63, 98 }, { 67, 79, 83, 75 },
            { 90, 76, 65, 60 }, { 84, 88, 63, 79 }, { 72, 66, 58, 77 } };

    public double avg(String name) {
        double sum = 0.0;
        if (name.equalsIgnoreCase("java")) {
            for (int i = 0; i < score[i].length; i++) {
                sum += score[i][0];
            }
        }
        if (name.equalsIgnoreCase("C++")) {
            for (int i = 0; i < score[i].length; i++) {
                sum += score[i][1];
            }
        }
        if (name.equalsIgnoreCase("Oracle")) {
            for (int i = 0; i < score[i].length; i++) {
                sum += score[i][2];
            }
        }
        if (name.equalsIgnoreCase("Android")) {
            for (int i = 0; i < score[i].length; i++) {
                sum += score[i][3];
            }
        }
        return sum/5;
    }
    public double sum(String name){
        double sum = 0.0;
        if (name.equalsIgnoreCase("张三丰")) {
            for (int i = 0; i < score[i].length; i++) {
                sum += score[0][i];
            }
        }
        if (name.equalsIgnoreCase("郭靖")) {
            for (int i = 0; i < score[i].length; i++) {
                sum += score[1][i];
            }
        }
        if (name.equalsIgnoreCase("乔峰")) {
            for (int i = 0; i < score[i].length; i++) {
                sum += score[2][i];
            }
        }
        if (name.equalsIgnoreCase("张无忌")) {
            for (int i = 0; i < score[i].length; i++) {
                sum += score[3][i];
            }
        }
        if (name.equalsIgnoreCase("杨过")) {
            for (int i = 0; i < score[i].length; i++) {
                sum += score[4][i];
            }
        }

        return sum;
    }
    public void sort(String name){
        if (name.equalsIgnoreCase("java")) {
            System.out.println("乔峰,张三丰,张无忌,杨过,郭靖");
        }
        if (name.equalsIgnoreCase("C++")) {
            System.out.println("张无忌,郭靖,张三丰,乔峰,杨过");
        }
        if (name.equalsIgnoreCase("oracle")) {
            System.out.println("郭靖,乔峰,张三丰,张无忌,郭靖");
        }
        if (name.equalsIgnoreCase("Android")) {
            System.out.println("张三丰,张无忌,杨过,郭靖,乔峰");
        }
    }
    public static double get(String uName, String cName) {
        int i = 0, j = 0;
        if (uName.equalsIgnoreCase("张三丰")) {
            i = 0;
        } else if (uName.equalsIgnoreCase("郭靖")) {
            i = 1;
        } else if (uName.equalsIgnoreCase("乔峰")) {
            i = 2;
        } else if (uName.equalsIgnoreCase("张无忌")) {
            i = 3;
        } else if (uName.equalsIgnoreCase("杨过")) {
            i = 4;
        }
        if (cName.equalsIgnoreCase("java")) {
            j = 0;
        } else if (uName.equalsIgnoreCase("c++")) {
            j = 1;
        } else if (uName.equalsIgnoreCase("Oracle")) {
            j = 2;
        } else if (uName.equalsIgnoreCase("Android")) {
            j = 3;
        }

        return score[i][j];
    }

}

class Person{
     String name;
     Calendar birthday;
     boolean gender; //男女
    Person partner;

    public Person(String name, Calendar birthday, boolean gender, Person partner) {
        this.name = name;
        this.birthday = birthday;
        this.gender = gender;
        this.partner = partner;
    }

    public  boolean marry(Person p){
        if(this.gender == p.gender){
            System.out.println("同性别不可以结婚！");
            return false;
        }
        if(this.partner!=null || p.partner!=null){
            System.out.println("一方已婚，不能再次结婚！");
            return false;
        }
        if(!this.wasmarry()){
            System.out.println("你没有达到结婚年龄，不能结婚！");
            return false;
        }
        if(!p.wasmarry()){
            System.out.println("你的对象没有达到结婚年龄，不能结婚");
            return  false;
        }
        this.partner = p;
        p.partner = this;
        System.out.println("恭喜，可以结婚！");
        return true;
    }
    public int getAge() {//获得年龄的方法
        Calendar today = new GregorianCalendar();//当前的日期
        int todayYear = today.get(Calendar.YEAR);
        int todayMonth = today.get(Calendar.MONTH);
        int todayDay = today.get(Calendar.DAY_OF_MONTH);
        int birthYear = birthday.get(Calendar.YEAR);
        int birthMonth = birthday.get(Calendar.MONTH);
        int birthDay = birthday.get(Calendar.DAY_OF_MONTH);

        if (todayMonth > birthMonth) {
            return todayYear - birthYear;
        } else if (todayMonth < birthMonth) {
            return todayYear - birthYear - 1;
        } else if (todayDay >= birthDay) {
            return todayYear - birthYear;
        } else {
            return todayYear - birthYear - 1;
        }
    }
    public boolean wasmarry(){
        //true为男
        if(this.gender&&this.getAge()>=22){
            return true;
        }
        //false为女
        if(!this.gender&&this.getAge()>=20){
            return true;
        }
        return false;
    }

}

class MobileShop{
    private int mobileAmount;
    InnerPurchaseMoney innerPurchaseMoney1;
    InnerPurchaseMoney innerPurchaseMoney2;

    public MobileShop() {
        innerPurchaseMoney1 = new InnerPurchaseMoney(20000);
        innerPurchaseMoney2 = new InnerPurchaseMoney(10000);
    }
    class InnerPurchaseMoney{
        int moneyValue;

        public InnerPurchaseMoney(int moneyValue) {
            this.moneyValue = moneyValue;
        }
        void buyMobile(){
            if (moneyValue>=20000){
                mobileAmount-=6;
                System.out.println("用价值"+moneyValue+"的内部购物卷买了6部手机");
            }else if(moneyValue<20000&&moneyValue>=10000){
                mobileAmount-=3;
                System.out.println("用价值"+moneyValue+"的内部购物卷买了3部手机");
            }
        }
    }

    public int getMobileAmount() {
        return mobileAmount;
    }

    public void setMobileAmount(int mobileAmount) {
        this.mobileAmount = mobileAmount;
    }
}

class Falimy{
    TV homeTV;
    void buyTV(TV tv){
        homeTV = tv;
    }
    void remoteControl(int m){
        homeTV.setChannel(m);
    }
    void seeTV(){
        homeTV.showProgram();
    }
}

class TV{
    private int channel;//频道

    public int getChannel() {
        return channel;
    }

    public void setChannel(int m) {
       if(m>=1){
           channel = m;
       }
    }
    void showProgram(){
        switch (channel){
            case 1:
                System.out.println("中央一台");
                break;
            case 2:
                System.out.println("中央二台");
                break;
            case 3:
                System.out.println("中央三台");
                break;
            case 4:
                System.out.println("体育频道");
                break;
            case 5:
                System.out.println("中央五台");
                break;
            default:
                System.out.println(channel+"不能收看");
        }
    }
}

class Bank{
    int year = 0;
    int savedMoney = 0;
    double interest = 0.0;
    double rate = 0.35;

    double computerInterest(){
        interest=year*rate*savedMoney;
        return interest;
    }
}
class ConstructionBank extends Bank{
    private double  year = 0.0;

    private double rate = 0.0;


    @Override
    double computerInterest() {
        super.year = (int)year;
        super.rate = rate;
        super.computerInterest();

        int day = (int)((year-super.year)*1000);
        interest+=day*rate/365*savedMoney;
        System.out.println(savedMoney+"元在建设银行"+super.year+"年"+day+"天的利息是"+interest+"元");

        return interest;
    }
    public double getYear() {
        return year;
    }

    public void setYear(double year) {
        this.year = year;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }
}
class BankOfDalian extends Bank{
    private  double year;

    @Override
    double computerInterest() {
        super.year = (int)year;
        super.computerInterest();
        int day = (int)((year - super.year)*1000);
        interest += day * rate / 365 *savedMoney;
        System.out.println(savedMoney + "元在大连银行" + super.year + "年" + day + "天的利息：" + interest + "元" );
        return interest;
    }

    public double getYear() {
        return year;
    }

    public void setYear(double year) {
        this.year = year;
    }

}

interface ComputeWeight{
    public double computeWeight();

}
class Televsion implements ComputeWeight{

    @Override
    public double computeWeight() {
        double tv_w = Math.random()*100;
        return tv_w;
    }
}
class Computer implements ComputeWeight{

    @Override
    public double computeWeight() {
        double c_w = Math.random()*100;
        return c_w;
    }
}

class Wash implements ComputeWeight{

    @Override
    public double computeWeight() {
        double x_w = Math.random()*100;
        return x_w;
    }
}
class Truck{
    ComputeWeight[] goods;
    double totalW = 0;

    public Truck(ComputeWeight[] goods) {
        this.goods = goods;
    }
    public void setGoods(ComputeWeight[] goods) {
        this.goods = goods;
    }

    public double getTotalW() {
        totalW = 0;
        for (int i = 0; i < goods.length; i++) {
            totalW += goods[i].computeWeight();

        }
        return totalW;
    }
}

public class Test1 {


    public static void main(String[] args) {
        for(int i=1;i<=10;i++){
            if(i%2 == 0 | i%5==0){
                continue;
            }
            System.out.print(i+"\t");}



    }

    public static void main15(String[] args) {
        ComputeWeight[] goods = new ComputeWeight[650];
        for (int i = 0; i < goods.length; i++) {
            if(i%3 == 0){
                goods[i] = new Televsion();
            }else if(i%3 == 1){
                goods[i] = new Computer();
            }else if(i%3 == 2){
                goods[i] = new Wash();
            }
        }
        Truck truck = new Truck(goods);
        System.out.printf("\n货车装载的货物重量:%-8.5f kg\n",truck.getTotalW());
        goods = new ComputeWeight[68];
        for (int i = 0; i < goods.length; i++) {
            if(i%2 == 0){
                goods[i] = new Televsion();
            }else{
                goods[i] = new Wash();
            }
        }
        truck.setGoods(goods);
        System.out.printf("货车装载的货物重量:%-8.5f kg\n",truck.getTotalW());
    }
    //2.银行计算利息
    public static void main14(String[] args) {
        Scanner sc = new Scanner(System.in);
        ConstructionBank bank1 = new ConstructionBank();
        BankOfDalian bank2 = new BankOfDalian();

        System.out.println("请输入存款金额：>");
        bank1.savedMoney = sc.nextInt();
        bank2.savedMoney = bank1.savedMoney;
        System.out.println("建设银行存款利率：>");
        bank1.setRate(sc.nextDouble());
        System.out.println("存款时长：>");
        bank1.setYear(sc.nextDouble());
        bank2.setYear(bank1.getYear());
        bank1.computerInterest();

        System.out.println("大连银行的存款利率：>");
        bank2.rate = sc.nextDouble();
        bank2.computerInterest();
        System.out.println("两家银行利息相差："+Math.abs(bank1.interest-bank2.interest)+"元");
    }


    //1.家中的电视
    public static void main13(String[] args) {

        TV haierTV = new TV();
        haierTV.setChannel(1);
        System.out.println("haierTV的频道是："+haierTV.getChannel());

        Falimy zhangSanFamily = new Falimy();
        zhangSanFamily.buyTV(haierTV);
        System.out.println("zhangsanFamily开始看节目，正在看的是：");
        zhangSanFamily.seeTV();

        int m = 5;
        System.out.println("zhangsanFamily将电视更换到"+m+"频道");
        zhangSanFamily.remoteControl(m);
        System.out.println("haierTV的频道是："+haierTV.getChannel());
        System.out.println("zhangsanFamily开始看节目，在看的节目是：");
        zhangSanFamily.seeTV();


}
    //内部购物券
    public static void main12(String[] args) {
        MobileShop mobileShop = new MobileShop();
        mobileShop.setMobileAmount(60);
        System.out.println("手机专卖店目前有:"+mobileShop.getMobileAmount()+"部手机");
        mobileShop.innerPurchaseMoney1.buyMobile();
        mobileShop.innerPurchaseMoney2.buyMobile();
        System.out.println("手机专卖店目前有:"+mobileShop.getMobileAmount()+"部手机");
    }
    //1.人类的抽象
    public static void main11(String[] args) {
        Person xiaowang = new Person("小王",Calendar.getInstance(),true,null);
        Person fangfang = new Person("芳芳",Calendar.getInstance(),false,null);
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();
        xiaowang.birthday.set(Calendar.YEAR,2005);
        fangfang.birthday.set(Calendar.YEAR,1990);
        boolean mcase = xiaowang.marry(fangfang);
        System.out.println(mcase);

    }

    //2. 成绩统计程序
    public static void main10(String[] args) {
        Score d = new Score();
        Scanner s = new Scanner(System.in);
        while (true) {
            System.out.println("请输入查询命令：");
            String comm = s.next();
            double avg = 0;
            if (comm.equalsIgnoreCase("AVG")) {
                System.out.println("请输入课程名称：");
                String course = s.next();
                avg = d.avg(course);
                System.out.println(course + "这门课的平均分是：" + avg);

            } else if (comm.equalsIgnoreCase("sum")) {
                System.out.println("请输入要查询的学生姓名：");
                String name = s.next();
                double sum = d.sum(name);
                System.out.println(name + "的总分是：" + sum);
            } else if (comm.equalsIgnoreCase("sort")) {
                System.out.println("请输入课程名称：");
                String course = s.next();
                d.sort(course);
            } else if (comm.equalsIgnoreCase("get")) {
                System.out.println("请输入学生姓名：");
                String name = s.next();
                System.out.println("请输入课程名称：");
                String course = s.next();
                double score = d.get(name, course);
                System.out.println(name + "的" + course + "的成绩是：" + score);
            } else if (comm.equals("EXIT")) {
                break;
            }
        }

    }

    //1. 酒店前台管理程序
    public static void main9(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Room room = new Room();
        while(true){
            System.out.println("请输入命令：>");
            String comm = scanner.next();
            if(comm.equalsIgnoreCase("search")){
                room.show();
            }else if(comm.equalsIgnoreCase("in")){
                System.out.println("请输入客户姓名:>");
                String name = scanner.next();
                System.out.println("客户的房间号是:>");
                int hao = scanner.nextInt();
                room.inRoom(name,hao);
            }else if(comm.equalsIgnoreCase("out")){
                System.out.println("请输入所退的房间号是:>");
                int hao = scanner.nextInt();
                room.outRoom(hao);
            }else if(comm.equalsIgnoreCase("exit")){
                break;
            }
        }

    }

    //4. 设计一个随机点名器
    public static void main8(String[] args) {

        Scanner sc =new Scanner(System.in);
        System.out.println("************随机点名器*********");
        String[] student = new String[6];
        for (int i = 0; i < student.length; i++) {
            System.out.println("输入第"+(i+1)+"学生名字:>");
            student[i] = sc.next();
        }
        for (int i = 0; i < student.length; i++) {
            System.out.print(student[i] + "\t");
        }
        System.out.println();
        //获取随机数，
        int index = new Random().nextInt(student.length);

        String name = student[index];
        System.out.println("被点名同学的姓名是:>"+name);
    }

    //3. 定义一个有5行元素的整型二维数组
    public static void main7(String[] args) {

        //1.
        int[][] arr = new int[5][];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = new int[i+1];
        }
        //2.
        /*int[][] arr = new int[5][5];*/
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j <= i; j++) {
                arr[i][j] = i+1;
                System.out.print(arr[i][j] + " ");
            }
            System.out.println("");
        }
    }

    //1. 用二维数组保存一首唐诗，每一行代表一句
    public static void main6(String[] args) {
        String poemTitle = "劝学诗";
        String poet = "赵恒";
        //外循环从左到右
        //内循环每列从下往上
        char[][] poem = {
                {'富','家','不','用','买','良','田'},
                {'书','中','自','有','千','钟','粟'},
                {'安','居','不','用','架','高','堂'},
                {'书','中','自','有','黄','金','屋'},
                {'出','门','无','车','毋','须','恨'},
                {'书','中','有','马','多','如','簇'},
                {'娶','妻','无','媒','毋','须','恨'},
                {'书','中','有','女','颜','如','玉'},
                {'男','儿','欲','遂','平','生','志'},
                {'勤','向','窗','前','读','六','经'}
        };
        System.out.println("\t"+poemTitle);
        System.out.println("\t\t\t"+poet);
        System.out.println("--------------------------------");

        for (int i = 0; i < poem[0].length; i++) {
            for (int j = 0; j < poem.length; j++) {
                System.out.print(poem[poem.length-1-j][i]+" ");


            }
            System.out.println();
        }

    }
    //学生成绩等级判断
    public static void main5(String[] args) {
        Scanner sc =new Scanner(System.in);
        System.out.println("请输入学生成绩:>");
        int cj = sc.nextInt();
        if(cj>0&&cj<=100){
            cj=cj/10;
            switch (cj){
                case 9: case 10:
                    System.out.println("A");
                    break;
                case 8:
                    System.out.println("B");
                    break;
                case 7:
                    System.out.println("C");
                    break;
                case 6:
                    System.out.println("D");
                    break;
                default:
                    System.out.println("E");
                    break;
            }
        }else{
            System.out.println("输入成绩无效");
        }
    }

    //某电信公司手机通话费计费程序
    public static void main4(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入国内通话时长:>");
        double tonghua = sc.nextDouble();
        System.out.println("请输入短信条数:>");
        double duanxin = sc.nextDouble();
        System.out.println("请输入数据流量:>");
        double liuliang = sc.nextDouble();

        double taocan = 58;
        if(tonghua>250){
            taocan +=Math.ceil(tonghua-250)*0.25;
        }
        if(duanxin>100){
            taocan +=(duanxin-100)*0.1;
        }
        if(liuliang>50){
            taocan +=Math.ceil(liuliang-50)*0.3;
        }
        System.out.println("本月消费:>"+taocan);
    }

    //个人所得税
    public static void main3(String[] args) {
        Scanner sc = new Scanner(System.in);
        double income = sc.nextDouble();
        //月应纳税所得额 = 月实际收入-3500
        double taxSalary = income -3500;
        double tax = 0.0;

        if(taxSalary<=0){
            tax = 0.0;
        }else if(taxSalary>0&&taxSalary<1500){
            tax = taxSalary*0.03;
        }else if(taxSalary>=1500&&taxSalary<4500){
            tax = 1500 * 0.03 + (taxSalary - 1500) * 0.1;
        }else if(taxSalary>=4500&&taxSalary<9000){
            tax = 1500 * 0.03 + 3000 * 0.1 +(taxSalary - 4500) * 0.20;
        }else if(taxSalary>=9000&&taxSalary<35000){
            tax = 1500 * 0.03 + 3000 * 0.1 + 4500 * 0.20 + (taxSalary - 9000) * 0.25;
        }else if(taxSalary>=35000&&taxSalary<55000){
            tax = 1500 * 0.03 + 3000 *0.1 + 4500 * 0.20 + 26000 *0.25 + (taxSalary - 35000)*0.30;
        }else if(taxSalary>=55000&&taxSalary<80000){
            tax = 1500 * 0.03 + 3000 *0.1 + 4500 * 0.20 + 26000 *0.25 + 20000*0.30+(taxSalary-55000)*0.35;
        }else if(taxSalary>=80000){
            tax = 1500 * 0.03 + 3000 *0.1 + 4500 * 0.20 + 26000 *0.25 + 20000*0.30+25000*0.35 + (taxSalary -80000)*0.45;
        }

        System.out.println("实际收入：>"+income);
        System.out.println("应纳的税额:>"+taxSalary);
        System.out.println("个人所得税:>"+tax);
        System.out.println("税后的收入:>"+(income-tax));


    }

    //摄氏温度与华氏温度的转换
    public static void main2(String[] args) {
        Scanner sc = new Scanner(System.in);
        int wendu = sc.nextInt();
        char falg = sc.next().trim().charAt(0);
        //摄氏温度 -》华氏温度
        if(falg == 'C'||falg == 'c'){
            double f_temp = 9*wendu/5.0+32;
            //四舍五入
            int huashi = (int)(f_temp+0.5);
            System.out.println("输入:>"+wendu+" C");
            System.out.println("转换后:>"+huashi+" F");
        }else if(falg == 'f'||falg == 'F'){
            double c_temp = 5*(wendu-32)/9*wendu;
            //四舍五入
            int sheshi = (int)(c_temp+0.5);
            System.out.println("输入:>"+wendu+" F");
            System.out.println("转换后:>"+sheshi+" C");
        }
    }
    //某航空公司航班班期查询程序
    public static void main1(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入班期：");
        byte num = (byte) sc.nextInt();
        String[] datavalue = {"周日","周一","周二","周三","周四","周五","周六"};
        for (int i = 0; i < datavalue.length; i++) {
            //判断语句：(num&(1<<i))!=0
            if((num&(1<<i))!=0){
                //15 00001111
                System.out.println(datavalue[i]+" ");
            }
        }
    }
}


